/**
 * AdminController
 *
 * @description :: Server-side logic for managing admins
 * @help        :: See http://sailsjs.org/#!/documentation/concepts/Controllers
 */

module.exports = {

  login: function (req, res) {
    res.view('admin/login', {layout: 'admin/login_layout'});
  },

  authenticate: function (req, res) {
    var user_name = req.body.user_name;
    var passwd = req.body.passwd;
    if (user_name == 'admin' && passwd == 'rongdi12345') {
      req.session.user_id = 'admin';
      res.redirect('/admin');
    } else {
      res.send('用户名或密码错误')
    }
  },

  index: function (req, res) {
    if (!req.session.user_id) {
      res.redirect('/admin/login')
    } else {
      res.view('admin/index', {layout: 'admin/layout'});
    }
  }
};

